<?php
/**
 * DBShop 电子商务系统
 *
 * ==========================================================================
 * @link      https://www.dbshop.net/
 * @copyright 北京珑大钜商科技有限公司，并保留所有权利。
 * @license   https://www.dbshop.net/license.html License
 * ==========================================================================
 *
 * @author    静静的风 <baron@loongdom.cn>
 *
 */

namespace Goods\Repository;

use Doctrine\ORM\EntityRepository;
use Goods\Entity\GoodsOtherTag;
use Goods\Entity\GoodsOtherTagGoods;

class GoodsOtherTagRepository extends EntityRepository
{
    /**
     * 聚合标签列表
     * @return float|int|mixed|string
     */
    public function findOtherTagList()
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $query->select('ot')
            ->addSelect('(SELECT COUNT(g.otherTagGoodsId) FROM '.GoodsOtherTagGoods::class.' AS g WHERE g.otherTagId=ot.otherTagId) AS goodsNum')
            ->from(GoodsOtherTag::class, 'ot')
            ->orderBy('ot.otherTagId', 'DESC');

        return $query->getQuery()->getResult();
    }
}